<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
</head>

<body>
    <div>这是第1个div</div>
    <div>这是第2个div</div>
    <div>这是第3个div</div>
    <div>这是第4个div</div>
    <div>这是第5个div</div>

    <script>
        (function(window, undefined) {
            // jQuery => 工厂函数
            var jQuery = function(selector) {

                return new jQuery.fn.init(selector);
            };

            // 原型替换
            jQuery.fn = jQuery.prototype = {
                constructor: jQuery,

                init: function(selector) {
                    var elements = document.querySelectorAll(selector);
                    [].push.apply(this, elements); // this => 指向了init的实例对象
                },
                css: function() {
                    console.log("css is ok");
                },
            };

            window.jQuery = window.$ = jQuery;
        })(window);

        var $divs = $("div");
        console.log($divs);
    </script>
</body>

</html>